<template>
	<view class="box">
		<!-- 注释 -->
		<view class="tips red tr">注：礼品卡如果不兑换，需一次性使用完，不找零</view>
		<!-- 使用记录 -->
		<view class="cord" :class="card.length>0?'bgc':''">
			<text @click="goDesc">使用说明＞</text>
		</view>
		<!-- 空 -->
		<view class="none" v-if="!card.length">
			<view class="none-img f-w">
				<image src="https://jw.xzsw2021.com/static/big/icon_225@2x.png" mode=""></image>
			</view>
			<view class="f30 tr c666">暂时没有任何礼品卡哦</view>
		</view>
		<!-- 列表 -->
		<view class="list" v-else>
			<view class="card" v-for="(item,index) of card" :key="index">
				<view class="one bold f28 hide-line2">{{item.title}}</view>
				<view class="two f26 f-w">
					{{item.code}} <text class="orange" @click="copy(item.code)">复制</text>
				</view>
				<view class="three fw-bt">
					<view class="f-w">
						<view class="f30 red">￥<text class="f36 bold">{{item.amount}}</text></view>
						<view class="f24 orange" @click="shiyong(item.id)">直接使用＞</view>
					</view>
					<view class="btn" @click="shareCard(item)">
						<button open-type="share"
							style="position: absolute;width: 100%;height: 100%;opacity: 0;top: 0;">
						</button>
						去赠送
					</view>
					<view class="btn" @click="duihuan(item.id)">兑换到余额</view>
				</view>
			</view>
		</view>

		<view class="" style="height: 130rpx;"></view>
		<view class="btn22" @click="goCenter">购买礼品卡</view>

	</view>
</template>

<script>
	import {
		getUserCardListApi
	} from '@/api/user.js'
	export default {
		data() {
			return {
				card: [],
				search: {
					page: 1,
					limit: 15,
					status: 0
				},
				shareData: {}
			}
		},
		onReachBottom() {
			this.search.page += 1
			this.cardList()
		},
		created() {
			this.cardList()
		},
		onShareAppMessage(res) {
			console.log(this.shareData)
			console.log(res)
			return {
				title: this.shareData.title,
				// imageUrl: require('@/static/img/card.png'),
				imageUrl: '/static/img/card.png',
				path: `/pages/index/index?card_share=${this.shareData.uni}&card_id=${this.shareData.id}&spread_spid=${this.shareData.uid}`,
			}
		},
		methods: {
			shareCard(item) {
				this.shareData = item
			},
			cardList() {
				getUserCardListApi(this.search).then(res => {
					this.card.push(...res.data.data)
				}).catch(err => {

				})
			},

			goCenter() {
				uni.navigateTo({
					url: '/pages/user/mygiftcard/buycard'
				})
			},

			// 使用说明
			goDesc() {
				console.log('使用说明');
				uni.navigateTo({
					url: '/pages/xieyi/xieyi?type=9'
				})
			},
			// 复制
			copy(value) {
				this.$copy(value)
			},
			// 直接使用
			shiyong(id) {
				let url = '/pages/index/index'
				uni.switchTab({
					url: url,
					fail: (err) => {
						uni.navigateTo({
							url: url
						})
					}
				})
			},
			// 兑换到余额
			duihuan(id) {
				uni.navigateTo({
					url: `/pages/user/mygiftcard/duihuan/duihuan?id=${id}`
				})
			}
		}
	}
</script>
<style>
	page {

		background-color: #F5F5F5;
	}
</style>
<style lang="scss" scoped>
	.box {
		.tips {
			width: 750rpx;
			height: 64rpx;
			line-height: 64rpx;
			font-size: 24rpx;
			background: #FEF6F6;
		}

		.cord {
			padding: 18rpx 30rpx;
			font-size: 26rpx;
			text-align: right;
			color: #F45E14;
		}

		.bgc {
			background-color: #F5F5F5;
		}

		.none {
			.none-img {
				margin: 148rpx auto 160rpx;
				width: 413rpx;
				height: 243rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.orange {
			color: #F45E14;
		}

		.list {

			padding: 0 30rpx 30rpx;
			box-sizing: border-box;
			box-sizing: border-box;

			.card {
				position: relative;
				width: 690rpx;
				margin-bottom: 20rpx;
				padding: 30rpx 30rpx;
				// height: 220rpx;
				background: #FFFFFF;
				border-radius: 10rpx;
				box-sizing: border-box;

				.two {
					margin: 10rpx 0 34rpx;

					&>text {
						margin-left: 10rpx;
						text-decoration: underline;
					}
				}

				.three {
					.red {
						margin-right: 22rpx;
					}
				}

				.btn {
					width: 180rpx;
					height: 54rpx;
					line-height: 54rpx;
					font-size: 26rpx;
					text-align: center;
					color: #F83535;
					background: #FFFFFF;
					border: 1rpx solid #F83535;
					position: relative;
					border-radius: 27rpx;
				}
			}
		}
	}

	.btn22 {
		position: fixed;
		bottom: 60rpx;
		left: 50rpx;
		// transform: translateX(-50%);
		width: 650rpx;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		color: #F83535;
		font-size: 28rpx;
		background: #FFFFFF;
		border: 1rpx solid #F83535;
		border-radius: 45rpx;
		z-index: 101;
	}
</style>
